package one;
import java.util.*;

public class A008 {

    public int lengthOfLongestSubstring(String s) {
        Set<Character> set = new HashSet<>();
        char[] str = s.toCharArray();
        int left=0;
        int ret=0;
        for(int right=0;right<str.length;right++) {
            //2.判断
            while(set.contains(str[right])) {
                set.remove(str[left++]);
            }
            //3.记录结果
            ret = Math.max(ret,right-left+1);
            //1.入窗口
            set.add(str[right]);
        }
        return ret;
    }
}
